fn main() {
    println!("新类型");

    struct Years(u32);
    struct Days(u32);

    // 年日转换, 转换时必须用特定的类型,才能拥有相应的 方法
    impl Years {
        pub fn to_days(&self) -> Days {
            Days(self.0 * 365)
        }
    }
    impl Days {
        pub fn to_years(&self) -> Years {
            Years(self.0 / 365)
        }
    }

    fn old_enought(age: &Years) -> bool {
        age.0 >= 18
    }

    let age = Years(5);
    println!("{} 岁 活了 {} 天", age.0, age.to_days().0);
    println!("成年了吗?{}", old_enought(&age.to_days().to_years())); // years->days->years

    // old_enought(age.to_days()); // 类型约束: expected `&Years`, found struct `Days`
}
